import { defHttp } from '@/utils/http/axios';
import { UserModel, ChangePasswordParams, GetUserListParams, CreateUserParams, UpdateUserParams, ResetPasswordParams } from './model/user';
import { BasicFetchResult } from '@/api/model/baseModel'

import { ErrorMessageMode } from '#/axios';

export function getMe() {
  return defHttp.get<UserModel>(
    {
      url: '/account/users/me',
    },
    {
      errorMessageMode: 'none'
    }
  );
}

export function changePassword(params: ChangePasswordParams, mode: ErrorMessageMode = 'message') {
  return defHttp.post(
    {
      url: '/account/users/change-password',
      params,
    },
    {
      errorMessageMode: mode,
      successMessageMode: mode,
    }
  );
}

export function resetPassword(params: ResetPasswordParams, mode: ErrorMessageMode = 'message') {
  return defHttp.post(
    {
      url: '/account/users/reset-password',
      params,
    },
    {
      errorMessageMode: mode,
      successMessageMode: mode,
    }
  );
}

export function getPermCode() {
  return
}

export function getUserList(params: GetUserListParams, mode: ErrorMessageMode = 'message') {
  return defHttp.get<BasicFetchResult<UserModel>>(
    {
      url: '/account/users',
      params,
    },
    {
      errorMessageMode: mode
    }
  );
}

export function createUser(params: CreateUserParams, mode: ErrorMessageMode = 'message') {
  return defHttp.post<UserModel>(
    {
      url: '/account/users',
      params,
    },
    {
      errorMessageMode: mode,
      successMessageMode: mode,
    }
  );
}

export function updateUser(id: number|string, params: UpdateUserParams, mode: ErrorMessageMode = 'message') {
  return defHttp.patch<UserModel>(
    {
      url: `/account/users/${id}`,
      params,
    },
    {
      errorMessageMode: mode,
      successMessageMode: mode,
    }
  );
}